// import React from "react";
import { getMenus } from '../../layout/layout.config'
import { Button } from 'antd';
import React, { useState } from 'react';
import { useDispatch, useSelector, useHistory } from 'dva'
export default () => {

  const dispatch = useDispatch()

  const history = useHistory()

  console.log(history.location.pathname)

  const menuChange = useSelector(({ menuChange }) => menuChange)

  const [defaultVal] = useState(() => {

    const menus = getMenus()

    let labelName = ''

    const findName = (arr) => {
      arr.forEach(item => {
        if (item.key === history.location.pathname) {
          labelName = item.label
          return
        }
        if (item.children) {
          findName(item.children)

        }

      })
    }
    findName(menus)
    return labelName
  })
  console.log(defaultVal, 'mornezhi ')
  const getVal = (e) => {
    const payload = {}
    payload[history.location.pathname] = e.target.value

    dispatch({
      type: 'menuChange/setVal',
      payload
    })
  }

  return (
    <div>
      <div>
        <div>
          输入同步
          <input type="text" onChange={getVal} defaultValue={menuChange[history.location.pathname] || defaultVal} />
        </div>
      </div>

    </div>
  )
}